﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace lcs.Web.materialinfo
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int mid=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(mid);
				}
			}
		}
			
	private void ShowInfo(int mid)
	{
		lcs.BLL.materialinfo bll=new lcs.BLL.materialinfo();
		lcs.Model.materialinfo model=bll.GetModel(mid);
		this.lblmid.Text=model.mid.ToString();
		this.txtproid.Text=model.proid;
		this.txtusework.Text=model.usework;
		this.txtprojectname.Text=model.projectname;
		this.txtprojecttype.Text=model.projecttype;
		this.txtsupplier.Text=model.supplier;
		this.txtmaterial.Text=model.material;
		this.txtnums.Text=model.nums.ToString();
		this.txtunit.Text=model.unit;
		this.txtsuppliername.Text=model.suppliername;
		this.txtsupplierphone.Text=model.supplierphone;
		this.txtmstatus.Text=model.mstatus.ToString();
		this.txtuid.Text=model.uid.ToString();
		this.txtmtype.Text=model.mtype.ToString();

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(this.txtproid.Text.Trim().Length==0)
			{
				strErr+="项目编号不能为空！\\n";	
			}
			if(this.txtusework.Text.Trim().Length==0)
			{
				strErr+="需用单位不能为空！\\n";	
			}
			if(this.txtprojectname.Text.Trim().Length==0)
			{
				strErr+="项目名称不能为空！\\n";	
			}
			if(this.txtprojecttype.Text.Trim().Length==0)
			{
				strErr+="项目类型不能为空！\\n";	
			}
			if(this.txtsupplier.Text.Trim().Length==0)
			{
				strErr+="供应商名称不能为空！\\n";	
			}
			if(this.txtmaterial.Text.Trim().Length==0)
			{
				strErr+="物料描述不能为空！\\n";	
			}
			if(!PageValidate.IsDecimal(txtnums.Text))
			{
				strErr+="数量格式错误！\\n";	
			}
			if(this.txtunit.Text.Trim().Length==0)
			{
				strErr+="单位不能为空！\\n";	
			}
			if(this.txtsuppliername.Text.Trim().Length==0)
			{
				strErr+="供应商联系人不能为空！\\n";	
			}
			if(this.txtsupplierphone.Text.Trim().Length==0)
			{
				strErr+="联系电话不能为空！\\n";	
			}
			if(!PageValidate.IsNumber(txtmstatus.Text))
			{
				strErr+="状态格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtuid.Text))
			{
				strErr+="物料员格式错误！\\n";	
			}
			if(!PageValidate.IsNumber(txtmtype.Text))
			{
				strErr+="物料类型格式错误！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int mid=int.Parse(this.lblmid.Text);
			string proid=this.txtproid.Text;
			string usework=this.txtusework.Text;
			string projectname=this.txtprojectname.Text;
			string projecttype=this.txtprojecttype.Text;
			string supplier=this.txtsupplier.Text;
			string material=this.txtmaterial.Text;
			decimal nums=decimal.Parse(this.txtnums.Text);
			string unit=this.txtunit.Text;
			string suppliername=this.txtsuppliername.Text;
			string supplierphone=this.txtsupplierphone.Text;
			int mstatus=int.Parse(this.txtmstatus.Text);
			int uid=int.Parse(this.txtuid.Text);
			int mtype=int.Parse(this.txtmtype.Text);


			lcs.Model.materialinfo model=new lcs.Model.materialinfo();
			model.mid=mid;
			model.proid=proid;
			model.usework=usework;
			model.projectname=projectname;
			model.projecttype=projecttype;
			model.supplier=supplier;
			model.material=material;
			model.nums=nums;
			model.unit=unit;
			model.suppliername=suppliername;
			model.supplierphone=supplierphone;
			model.mstatus=mstatus;
			model.uid=uid;
			model.mtype=mtype;

			lcs.BLL.materialinfo bll=new lcs.BLL.materialinfo();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","List.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
